package com.cooba.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.cooba.R;


public class ComfirmDialog extends Dialog implements
        android.view.View.OnClickListener {
    int layoutRes;// 布局文件
    Context context;
    private DialogListener listener;
    private TextView tvComfirm;

    public ComfirmDialog(Context context) {
        super(context);
        this.context = context;
    }

    /**
     * 自定义布局的构造方法
     *
     * @param context
     * @param resLayout
     */
    public ComfirmDialog(Context context, int resLayout) {
        super(context);
        this.context = context;
        this.layoutRes = resLayout;
    }

    /**
     * 自定义主题及布局的构造方法
     *
     * @param context
     * @param theme
     * @param resLayout
     */
    public ComfirmDialog(Context context, int theme, int resLayout,
                           DialogListener listener) {
        super(context, theme);
        this.context = context;
        this.layoutRes = resLayout;
        this.listener = listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(layoutRes);

        // 根据id在布局中找到控件对象
        tvComfirm = (TextView)findViewById(R.id.btn_comfirm);


        // 为按钮绑定点击事件监听器
      tvComfirm.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_comfirm:
                listener.comfirm();
                this.dismiss();
                break;

        }
    }

    public interface DialogListener {
        void comfirm();
    }


}